<?php
  // no direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
  jimport( 'joomla.application.component.view');
  
  class PicViewPic extends JView
  {              
    var $_name = "pic";
  
    function display()
    { 
      $this->displayList();
    }
    
    function displayList()
    {
      /* sorting */
      $state =& $this->get( 'state' );
            $lists['order_Dir'] = $state->get($this->_name . 'filter_order_Dir');
            $lists['order']     = $state->get($this->_name . 'filter_order');
            $this->assignRef('lists', $lists);    

      $pics = $this->get('ListData');
      if(empty($pics))
        $pics = array();

      $pics = $this->prepare_pics($pics);
      $this->assign('pics', $pics);
      $pagination = $this->get('Pagination');
      $this->assign('pagination', $pagination);
      
      JToolBarHelper::title( JText::_( 'Pics' ), 'generic.png' );
      
      JToolBarHelper::publishList();
      JToolBarHelper::unpublishList();
      JToolBarHelper::addNew();
      JToolBarHelper::editList();
      JToolBarHelper::deleteList();
      
      PBNYHelper::createMenu();
      
      parent::display("list");    
    }
    
    private function prepare_pics($pics){
      
      $mpic = $this->getModel('pic');
      
      foreach($pics as $pic)
        $pic->instance = strtoupper($mpic->get_pic_type_instance($pic->pic_type, $pic->pic_id));
      
      return $pics;
    }
    
    function displayAdd()
    {  
      $mpic  = $this->getModel('pic');    
      
      $this->assign("pic_types", $mpic->get_pic_types());
      
      JToolBarHelper::title( JText::_( 'Add Pic' ), 'generic.png' );
      JToolBarHelper::save();
      JToolBarHelper::cancel();

      parent::display("edit");
    }    
    
    function displayEdit()
    {  
      $mpic  = $this->getModel('pic');
      
      $cids  = JRequest::getVar('cid', null, 'default', 'array' );
      $pic   = $mpic->get($cids[0]);
      
      $this->assign("pic", $pic);
      $this->assign("pic_types", $mpic->get_pic_types());
      $this->assign("pic_type_instances", $mpic->get_pic_type_instances($pic->pic_type));
      
      JToolBarHelper::title( JText::_( 'Edit Pic' ), 'generic.png' );
      JToolBarHelper::save();
      JToolBarHelper::cancel();  

      parent::display("edit");
    }
  }
?>